package com.nemo.fenxiangs.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.nemo.fenxiangs.po.User;
import com.nemo.fenxiangs.service.UserService;

@Controller
public class UserController {
	@Autowired
	private UserService userService;
	@RequestMapping(value={"/addUser"},method={RequestMethod.GET,RequestMethod.POST})
	public String insertUser(User user) throws Exception{
		userService.insertItems(user);
		return "redirect:queryUser.action";
	}
	
	@RequestMapping(value={"/queryUser"},method={RequestMethod.GET,RequestMethod.POST})
	public String queryUser(Model model) throws Exception{
		List<User> userList = userService.findUserList();
		model.addAttribute("userList",userList);
		return "user/userList";
	}
	@RequestMapping(value={"/deleteUser"},method={RequestMethod.GET,RequestMethod.POST})
	public String deleteUserById(Integer[] user_id) throws Exception{
	
		for (Integer integer : user_id) {
			userService.deleteByPrimaryKey(integer);
		}
	
		return "redirect:queryUser.action";
	}
}
